package com.neusoft.SPNursingHome.controller;

import java.util.Map;

import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.prompt.Prompt;
import org.springframework.ai.chat.prompt.PromptTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/chatclient")
public class ChatClientController {
    private final ChatClient chatClient;

    public ChatClientController(ChatClient.Builder builder) {
        super();
        chatClient=builder.build();
        // TODO Auto-generated constructor stub
    }
    @GetMapping("/chat")
    public String chat(String msg){
        String result=chatClient.prompt("用猴哥语气回答").user(msg).call().content();
        return result;
    }
    @GetMapping("/explain")
    public String explain(String problem,String y) {
        String result=chatClient.prompt().system(x->{
                    x.text("以{style}语气回答问题").param("style",y);
                })
                .user(problem).call().content();
        return result;
    }
    @GetMapping("/prompt")
    public String prompt(String x) {
        PromptTemplate pt=new PromptTemplate("讲一个{topic}");
        Prompt prop=pt.create(Map.of("topic",x));
        String result=chatClient.prompt(prop).call().content();
        return result;
    }



}

